home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / gcctest / tests05.zoo / trandm.c < prev    next >
C/C++ Source or Header  |  1992-03-28  |  522b  |  40 lines

  1. #include <stdio.h>
  2. #if __STDC__
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5. #else
  6. #ifdef sun
  7. #define RAND_MAX 0x7fffffff
  8. #endif
  9. #endif
  10.  
  11. #if !__STDC__
  12. long labs(x)
  13. long x;
  14. {
  15.   return (x < 0)? -x : x;
  16. }
  17. #endif
  18.  
  19. #ifdef __hpux
  20. #define random rand
  21. #else
  22. extern long random();
  23. #endif
  24.  
  25. int main()
  26. {
  27.     register long i, h, t;
  28.     for (h = 0, t = 0, i = 0; i < 20000; i++)
  29.         if(random() < (RAND_MAX/2))
  30.             h++;
  31.         else
  32.             t++;
  33.         if(labs(h-t) > 2)
  34.         {
  35.         printf("%ld %ld\n", h , t);
  36.         return 1;
  37.         }
  38.         return 0;
  39. }
  40.